package com.sojoys.artifact.factory.template;

import java.io.IOException;

import org.beetl.core.Configuration;
import org.beetl.core.GroupTemplate;
import org.beetl.core.resource.ClasspathResourceLoader;
import org.beetl.core.resource.FileResourceLoader;

/**
 * @author : DengYing
 * @CreateDate : 2017年7月6日 上午10:28:31
 * @Description ：Please describe this document
 */
@SuppressWarnings("rawtypes")
public class BeetlTemplateFactory implements ITemplateFactory{
	@Override
	public IConfiguration classForTemplateLoading(Class<?> clazz, String rootPath) throws IOException {
		ClasspathResourceLoader resourceLoader = new ClasspathResourceLoader(clazz.getClassLoader(),rootPath);
		Configuration cfg = Configuration.defaultConfiguration();
		GroupTemplate gt = new GroupTemplate(resourceLoader, cfg);
		return new BeetlConfiguration(gt);
	}

	@Override
	public IConfiguration directoryForTemplateLoading(String rootPath) throws IOException {
		FileResourceLoader resourceLoader = new FileResourceLoader(rootPath,"utf-8");
		Configuration cfg = Configuration.defaultConfiguration();
		GroupTemplate gt = new GroupTemplate(resourceLoader, cfg);
		return new BeetlConfiguration(gt);
	}

}
